package com.cn.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cn.pojo.Qc_classify;
import com.cn.service.ProductServices;

@Controller
public class ProductController {

	@Resource
	private ProductServices productServices;
	//查看所有
	@RequestMapping(value = "productCategory")
	public ModelAndView showProduct(Model model) {
		ModelAndView view2 = new ModelAndView();
		view2.setViewName("adminFtl/product-category");
		List<Qc_classify> productAll = productServices.getProductAll();
		model.addAttribute("productAll", productAll);
		return view2;
	}

	@RequestMapping(value = "productCategoryAdd")
	public ModelAndView showProductAdd() {
		ModelAndView view = new ModelAndView();
		view.setViewName("adminFtl/product-category-add");
		return view;
	}
	
	//添加
	@RequestMapping(value="productCategoryAd")
	public String addProduct(Qc_classify classify,Model model){
		productServices.addProduct(classify);
		return "redirect:productCategory";
	}
	
	//删
	@RequestMapping(value="deleteProduct")
	public String deleteProduct(int c_id){
		productServices.deleteProduct(c_id);
		return "redirect:productCategory";
	}
	
	//查
	
	@RequestMapping(value="getSeachById")
	public String getSeachById(int cid,Model model){
		Qc_classify seachById = productServices.getSeachById(cid);
		model.addAttribute("seachById", seachById);
		return "adminFtl/product-category-add";	
	}
	//改
	@RequestMapping(value="updateProduct")
	public String updateProduct(Qc_classify classify){
		productServices.updateProduct(classify);
		 
		return  "redirect:productCategory";
		
	}
	
	@RequestMapping(value="result")
	public String result(){
		return "redirect:productCategory";
	}
	
	public void setProductServices(ProductServices productServices) {
		this.productServices = productServices;
	}
}
